package com.gmail.at.dao;

import java.util.List;

import org.joda.time.DateTime;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.gmail.at.model.Schedule;
import com.gmail.at.model.Train;

public interface ScheduleDAO extends PagingAndSortingRepository<Schedule, Integer> {
	
	@Query("SELECT s FROM Schedule s WHERE  s.train = :tr  AND " +
				"(s.dateOfDeparture BETWEEN :dateBegin AND :dateEnd) AND" +
				"(s.dateOfArrival BETWEEN :dateBegin AND :dateEnd)")
	public List<Schedule> findIsSchedulePossible(@Param("tr") Train train, @Param("dateBegin") DateTime begin,
			 @Param("dateEnd") DateTime end);
}
